package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
    /**
     * 根据菜品id查询套餐id
     * @param ids
     * @return
     */
    List<Long> getSetmealIdByDishId(List<Long> ids);

    /**
     * 插入新的套餐，并返回对应id
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into setmeal " +
            "(category_id, name, price, description, image, " +
            "create_time, update_time, create_user, update_user) " +
            "VALUES (#{categoryId},#{name},#{price},#{description}," +
            "#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(Setmeal setmeal);

    /**
     * 进行套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */

    Page<Setmeal> page(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 修改套餐
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 获取套餐信息
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);

    /**
     * 通过套餐id删除套餐
     * @param id
     */
    @Delete("delete from setmeal where id=#{id}")
    void delete(Long id);

    /**
     * 通过套餐id查询是否有状态为起售状态的套餐
     * @param ids
     * @param enable
     * @return
     */
    int getByIds(List<Long> ids, Integer enable);

    /**
     * 通过分类id查询相关的才套餐
     * @param category
     * @return
     */
    //@Select("select * from setmeal where category_id=#{id} and status=#{status}")
    List<Setmeal> getByCategoryId(Category category);
    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
